Fix streaming tool calls when reasoning parser is active#93
Fix streaming tool calls when reasoning parser is active#93janhilgard wants to merge 1 commit intowaybarrios:mainfrom
Conversation
The reasoning parser branch in stream_chat_completion() was missing tool call parsing entirely. When both --reasoning-parser and --tool-call-parser were enabled, streaming responses would emit raw tool call markup (e.g. <tool_call><function=...>) as plain content text instead of structured tool_calls objects. This adds tool call parsing to the reasoning parser branch, mirroring the existing logic in the standard (non-reasoning) path. Tool calls are now correctly detected, buffered during accumulation, and emitted as structured tool_calls with finish_reason="tool_calls". Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
@waybarrios, @janhilgard: status note plus coordination. This PR fixes the case where the reasoning parser branch in Coordination: at least two other PRs target the same problem area:
All three address the same root cause with slightly different approaches. They are also collectively the fix for issues #107 (Dubworx) and #161 (Thump604, "Reasoning content leaks into content field when tool calls are present"). Last activity Feb 16. This PR is the oldest of the three. Worth a coordination decision: which approach to land, then close or rebase the others. |
|
This PR is now superseded by #253 ("integrate tool call parser into reasoning parser streaming path") which was merged into The current This PR can be closed. |
Summary
--reasoning-parseris enabledstream_chat_completion()was skipping tool call parsing entirely, causing<tool_call>markup to leak intocontentinstead of being parsed into structuredtool_callsobjectsProblem
When both
--reasoning-parser deepseek_r1and--tool-call-parser hermesare enabled, streaming responses emit raw tool call markup as plain text:{"delta": {"content": "<tool_call>\n<function=get_weather>\n<parameter=location>\nPrague\n</parameter>\n</function>\n</tool_call>", "tool_calls": null}, "finish_reason": "stop"}Fix
After this change, tool calls are correctly parsed and emitted:
{"delta": {"tool_calls": [{"index": 0, "id": "call_4b99a63b", "type": "function", "function": {"name": "get_weather", "arguments": "{\"location\": \"Prague\"}"}}]}, "finish_reason": "tool_calls"}Test plan
--reasoning-parser deepseek_r1 --tool-call-parser hermesreturns structuredtool_callsfinish_reasonis"tool_calls"(not"stop")blackformatting passes🤖 Generated with Claude Code